﻿using Castle.Facilities.Logging;
using com.ytocargo.Application.SystemSettings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yto;
using Yto.Common.Extensions;
using Yto.Common.Dependency;
using Yto.Threading.BackgroundWorkers;

namespace Ytocargo.ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var launch = Launch.Startup<ConsoleAppModule>(CtnManager.Instance))
            {
                CtnManager.Instance.Container.AddFacility<LoggingFacility>(
                    f => f.UserBaseLogger()
                    .WithConfig("log4net.config")
                    );
                launch.Initialize();
            }
            bool isRunning = true;
            while (isRunning)
            {
                var key = Console.ReadLine();
                switch (key) {
                    case "run":
                        var services = CtnManager.Instance.Resolver<ISystemSettingsServices>();
                        services.ReadCsvFile();
                        break;
                    case "exit":
                        var backWorker = CtnManager.Instance.Resolver<IBackgroundManager>();
                        backWorker.Wait2Stop();
                        isRunning = false;
                        break;
                    default:
                        break;
                 }
            }
        }
    }
}
